const sqlite3 = require('../server/node_modules/sqlite3').verbose();
const path = require('path');

// 创建数据库连接
const dbPath = path.join(__dirname, '../resources/db/db.database');
console.log('Database path:', dbPath);

const db = new sqlite3.Database(dbPath);

// 查询所有表结构
db.serialize(() => {
  console.log('\n=== Database Tables ===');
  db.each("SELECT name FROM sqlite_master WHERE type='table'", (err, row) => {
    if (err) {
      console.error('Error:', err);
    } else {
      console.log('Table:', row.name);
    }
  }, () => {
    // 查看user_course_progress表结构
    console.log('\n=== User Course Progress Table Structure ===');
    db.each("SELECT sql FROM sqlite_master WHERE type='table' AND name='user_course_progress'", (err, row) => {
      if (err) {
        console.error('Error:', err);
      } else {
        console.log(row.sql);
      }
    }, () => {
      // 查看user_lesson_progress表结构
      console.log('\n=== User Lesson Progress Table Structure ===');
      db.each("SELECT sql FROM sqlite_master WHERE type='table' AND name='user_lesson_progress'", (err, row) => {
        if (err) {
          console.error('Error:', err);
        } else {
          console.log(row.sql);
        }
      }, () => {
        // 查看courses表结构
        console.log('\n=== Courses Table Structure ===');
        db.each("SELECT sql FROM sqlite_master WHERE type='table' AND name='courses'", (err, row) => {
          if (err) {
            console.error('Error:', err);
          } else {
            console.log(row.sql);
          }
        }, () => {
          // 查看lessons表结构
          console.log('\n=== Lessons Table Structure ===');
          db.each("SELECT sql FROM sqlite_master WHERE type='table' AND name='lessons'", (err, row) => {
            if (err) {
              console.error('Error:', err);
            } else {
              console.log(row.sql);
            }
          }, () => {
            db.close();
          });
        });
      });
    });
  });
});